<?php
namespace app\index\controller;
use think\Controller;
use think\DB;
use think\Request;

define('Salt','cdw');

class Index extends Controller
{


    public function index()
    {
    	$this->redirect('index/pdf');
        return $this->fetch();
    }

    public function pdf()
    {
        return $this->fetch('pdf/index');
    }
    public function edit1()
    {
        $info=Db::table('pdf2')->find();
        if(request()->isPost()){
            $form=input("post.");
            $result=DB::table('pdf2')->where(['id'=>1])->update($form);
            if($result){
                $this->success('成功', 'index/pdf');
            }else{
                $this->error('失败');
            }
        }

        $this->assign("info",$info);
        return $this->fetch('edit1/index');
    }
    public function edit2()
    {
        $info=Db::table('pdf1')->find();
        if(request()->isPost()){
            $form=input("post.");

            
            if(count(request()->file()['pic']) != 0){
            $files=request()->file('pic');

            foreach($files as $key=>$file){
                // 移动到框架应用根目录/uploads/ 目录下
                $info = $file->move( './pdf/uploads');
                $k=$key+1;
                if($info){
                    $form["pic{$k}"]=$info->getSaveName();
                }else{
                    // 上传失败获取错误信息
                   $this->error($file->getError());
                }    
            }

            }

            $result=DB::table('pdf1')->where(['id'=>1])->update($form);
            if($result){
                $this->success('成功', 'index/pdf');
            }else{
                $this->error('失败');
            }

        }

        $this->assign("info",$info);
        return $this->fetch('edit2/index');
    }


    public function view()
    {
        $info=Db::table('pdf2')->find();
        $this->assign("info",$info);
        return $this->fetch('view/index');
    }
    public function view2()
    {
        $info=Db::table('pdf2')->find();
        $this->assign("info",$info);
        return $this->fetch('view2/index');
    }
    public function view3()
    {
        $info=Db::table('pdf1')->find();
        $info['zip']=explode(",", $info['zip']);
        $count=count($info['zip'])-1;
        $this->assign("info",$info);
        $this->assign("count",$count);
        return $this->fetch('view3/index');
    }
}
